<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script type="text/javascript" src="../../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="../../../res/js/util.js"></script>
    <script type="text/javascript" src="../../../res/layui/layui.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

</head>
<body style="padding: 10px;">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>用户表增加及修改</legend>
</fieldset>

<form class="layui-form" action="" lay-filter='myform' id="myform">
    <input type="hidden" name="supId" id="supId">
    <div class="layui-form-item">
        <label class="layui-form-label">公司名称</label>
        <div class="layui-input-block">
            <input type="text" name="supName" id="supName" maxlength="10" lay-verify="required" autocomplete="off"
                   lay-reqtext="请输入公司名称" placeholder="请输入公司名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户电话</label>
        <div class="layui-input-block">
            <input type="text" name="supPhone" id="supPhone" maxlength="11" lay-verify="phone" autocomplete="off"
                   lay-reqtext="请输入电话" placeholder="请输入电话" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-block">
            <input type="text" name="supLinkman" id="supLinkman" maxlength="4" lay-verify="required" autocomplete="off" lay-reqtext="请输入联系人"
                   placeholder="请输入联系人" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">供货商地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" maxlength="20" lay-verify="required" autocomplete="off" lay-reqtext="请输入供货商地址"
                   placeholder="请输入供货商地址" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="ramark" id="ramark" maxlength="100" lay-verify="required"   autocomplete="off" lay-reqtext="请输入备注"
                   placeholder="请输入备注" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" layui-btn-normal  id="LAY-quxiao" >取消</button>
            <input type="button" class="layui-btn" lay-submit=""  lay-filter="myform" value="提交">
        </div>
    </div>
</form>

<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
//取到传过来的userId
        var supId = getQueryString("supId");

        if (supId) {
            var url = '../../../hqSupplier/selectOne';
            var data = {id: supId}
            //表单赋值
            $.get(url, data, function (obj) {
                console.info(obj);
                form.val('myform', obj);
            }, "json")
        }


        function getNow(s) {
            return s < 10 ? '0' + s : s;
        }

        setInterval(function getNow(s) {
            return s < 10 ? '0' + s : s;
        }, 1000);
        var myDate = new Date();
        var year = myDate.getFullYear();//获取当前年
        var month = myDate.getMonth() + 1;//获取当前月
        var date = myDate.getDate();//获取当前日
        var h = myDate.getHours();       //获取当前小时数(0-23)
        var m = myDate.getMinutes();     //获取当前分钟数(0-59)
        var s = myDate.getSeconds();
        var now = year + '-' + getNow(month) + "-" + getNow(date) + " " + getNow(h) + ':' + getNow(m) + ":" + getNow(s);
        //日期
        laydate.render({
            elem: '#userEstablishTime',
            format: 'yyyy-MM-dd HH:mm:ss',
            max: 'new Date()',//设置最大值为当前时间
            istime: true,//必须填入时间
            value: now,  //设置开始时间为当前时间
            theme: '##00ABB6'
        });
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });
        var num=0;
        //监听提交
        form.on('submit(myform)', function (data) {
            num++
            if (num===1){
                //获取所有的节点数据 包括父节点id
                var url="../../../hqSupplier/insert";
                var data2=data.field;
                //表单赋值
                $.post(url, data2, function (obj) {
                    console.info(obj)
                    if (obj.status === 1) {
                        //关闭当前弹出层
                        parent.closeOpen(obj.message);//调用父页面的关闭方法
                    }
                }, "json");
            }
        });

        //取消按钮
        layui.$('#LAY-quxiao').on('click', function (obj) {
            parent.quxiao();//调用父页面的取消方法
        });

    });
</script>

</body>
</html>